package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.DevMaintenanceTicketItemDao;
import com.sugon.entity.DevMaintenanceTicketItemEntity;
import com.sugon.modules.device.model.vo.DevMaintenanceTicketItemDetailVO;
import com.sugon.service.DevMaintenanceTicketItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 设备维护工单项Service实现类
 *
 * @author sugon
 * @date 2020-08-12 14:37:07
 */
@Service("devMaintenanceTicketItemService")
public class DevMaintenanceTicketItemServiceImpl implements DevMaintenanceTicketItemService {
    @Autowired
    private DevMaintenanceTicketItemDao devMaintenanceTicketItemDao;

    /**
     * queryObject
     *
     * @param id 主键
     * @return
     */
    @Override
    public DevMaintenanceTicketItemEntity queryObject(String id) {
        return devMaintenanceTicketItemDao.queryObject(id);
    }

    @Override
    public List<DevMaintenanceTicketItemDetailVO> queryByTicketId(String ticketId) {
        Map<String, Object> queryParam = MapUtil.newHashMap();
        queryParam.put("devMainTicketId", ticketId);
        return devMaintenanceTicketItemDao.queryAll(queryParam);
    }

    /**
     * queryList
     *
     * @param map 参数
     * @return
     */
    @Override
    public List<DevMaintenanceTicketItemEntity> queryList(Map<String, Object> map) {
        return devMaintenanceTicketItemDao.queryList(map);
    }

    /**
     * queryTotal
     *
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotal(Map<String, Object> map) {
        return devMaintenanceTicketItemDao.queryTotal(map);
    }

    /**
     * save
     *
     * @param devMaintenanceTicketItem 实体
     * @return
     */
    @Override
    public int save(DevMaintenanceTicketItemEntity devMaintenanceTicketItem) {
        devMaintenanceTicketItem.setId(RandomUtil.randomString(32));
        devMaintenanceTicketItem.setGmtCreate(DateUtil.date());
        // 默认为无异常清醒
        devMaintenanceTicketItem.setCheckResult(0);
        // 默认为未处理
        devMaintenanceTicketItem.setStatus(0);
        return devMaintenanceTicketItemDao.save(devMaintenanceTicketItem);
    }

    /**
     * update
     *
     * @param devMaintenanceTicketItem 实体
     * @return
     */
    @Override
    public int update(DevMaintenanceTicketItemEntity devMaintenanceTicketItem) {
        return devMaintenanceTicketItemDao.update(devMaintenanceTicketItem);
    }

    /**
     * delete
     *
     * @param id
     * @return
     */
    @Override
    public int delete(String id) {
        return devMaintenanceTicketItemDao.delete(id);
    }

    /**
     * deleteBatch
     *
     * @param ids
     * @return
     */
    @Override
    public int deleteBatch(String[] ids) {
        return devMaintenanceTicketItemDao.deleteBatch(ids);
    }

}
